package com.mhh.selary.backend.controller.api;

import com.mhh.selary.backend.api.api.ISelaryApiHttpService;
import com.mhh.selary.backend.dto.IdDTO;
import com.mhh.selary.backend.dto.api.ApiHttpCopyDTO;
import com.mhh.selary.backend.dto.api.ApiHttpMoveDTO;
import com.mhh.selary.backend.dto.api.ApiHttpRunDTO;
import com.mhh.selary.backend.dto.api.ApiHttpRunResultDTO;
import com.mhh.selary.backend.dto.api.ApiHttpSaveDTO;
import com.mhh.selary.backend.dto.api.ApiListDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author mhh
 * @date 2020-09-14 15:55:49
 */
@Slf4j
@RestController
@Api(tags = "Http接口管理")
@RequestMapping("/api/http")
public class ApiHttpController {

    @Autowired
    private ISelaryApiHttpService selaryApiHttpService;

    @PostMapping("listByGroup")
    @ApiOperation("分组下的api接口列表")
    public ApiListDTO listByGroup(@RequestBody IdDTO dto) {
        return ApiListDTO.builder().apiList(selaryApiHttpService.listByGroup(dto.getId())).build();
    }

    @PostMapping("saveApiHttp")
    @ApiOperation("保存api接口")
    public void saveApiHttp(@RequestBody ApiHttpSaveDTO dto) {
        selaryApiHttpService.saveApiHttp(dto);
    }

    @PostMapping("delApiHttp")
    @ApiOperation("删除api接口")
    public void delApiHttp(@RequestBody IdDTO dto) {
        selaryApiHttpService.delApiHttp(dto);
    }

    @PostMapping("detail")
    @ApiOperation("获取接口详情信息")
    public ApiHttpSaveDTO detail(@RequestBody IdDTO dto) {
        return selaryApiHttpService.detail(dto.getId());
    }

    @PostMapping("copyApiHttp")
    @ApiOperation("复制接口")
    public void copyApiHttp(@RequestBody ApiHttpCopyDTO dto) {
        selaryApiHttpService.copyApiHttp(dto);
    }

    @PostMapping("moveApiHttp")
    @ApiOperation("移动接口")
    public void moveApiHttp(@RequestBody ApiHttpMoveDTO dto) {
        selaryApiHttpService.moveApiHttp(dto);
    }

    @PostMapping("run")
    @ApiOperation("运行接口")
    public ApiHttpRunResultDTO run(@RequestBody ApiHttpRunDTO dto) {
        return selaryApiHttpService.run(dto);
    }
}
